<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>报价方案列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<script type="text/javascript">
	var grid = null;
	$(function () {
	    $("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/project/prjQuatPrpsCfgM/initList.do',
	    	method : 'get',
	        columns: [
	            { display: '方案配置名称',align: 'left',width: 150, enabledSort:true,
	            	render: function (rowdata, rowindex, value){
	            		var h='<a href="javascript:showDetail(';
	            		h+="'"+rowdata.id+"'";
	                    h+=')">'+rowdata.prpsCfgNm+'</a>';
	                	return h;
	            	}
	            },
	            /* { display: '所属机构', align: 'left',name: 'buOrgCdNm', width: 200, enabledSort:true}, */
	            { display: '业务类型', align: 'left',name: 'prjQuatPrpsAttrPageVO.bizTypCdNm', width: 100,isEllipsis: false },
	            { display: '项目类型', align: 'left',name: 'prjQuatPrpsAttrPageVO.prjTypCdNm', minWidth: 100,isEllipsis: false},
	            { display: '有效期', align: 'left',width: 180,
	            	render: function (rowdata, rowindex, value){
	            		var expStDt = new Date(rowdata.expStDt);
	    	    		var expStDtStr = DateUtils.formatDate(expStDt, DateUtils.YYYY_MM_DD);
	            		var expEndDt = new Date(rowdata.expEndDt);
	    	    		var expEndDtStr = DateUtils.formatDate(expEndDt, DateUtils.YYYY_MM_DD);
			            return expStDtStr + " / " + expEndDtStr;
	            	}	
	            },
	            { display: '状态', name: 'isValidNm', width: 50, enabledSort:true},
	            { display: '操作', width: 200 , align:'left',
	            	render: function (rowdata, rowindex, value){
	            		var h;
                        var h1='<a class="sq-button-hasicon" href="javascript:;" onclick="disable(';
                            h1+="'"+rowdata.id+"'";
                            h1+=')"><i class="sqBtnIco_13"></i>'+LogUtils.LOG_CMM_GRID_BTN_DISABLE+'</a>';
                            
                        var h2='<a class="sq-button-hasicon" href="javascript:;" onclick="enable(';
                            h2+="'"+rowdata.id+"'";
                            h2+=')"><i class="sqBtnIco_12"></i>'+LogUtils.LOG_CMM_GRID_BTN_ENABLE+'</a>';
                    	switch (rowdata.isValid){
                           case 0:
                               h=h2;
                               break;
                           case 1:
                               h=h1;
                               break;
                           default:
                           	h=h1;
                           	break;
                        }
                    	var g='<a class="sq-button-hasicon" href="javascript:change(';
	            		g+="'"+rowdata.id+"'";
	                    g+=')"><i class="sqBtnIco_4"></i>修改</a>';
                    	var d='<a class="sq-button-hasicon" href="javascript:deleteRecord(';
	            		d+="'"+rowdata.id+"'";
	                    d+=')"><i class="sqBtnIco_7"></i>删除</a>';
	                    var isSysDef = rowdata.isSysDef;
	            		if(isSysDef && isSysDef=="1"){
	            			return h;//内置方案木有修改也木有删除
	            		}
	                	return h + g + d;
	            	}
	            },
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        fixedCellHeight: false,
	        //isScroll: false,
	        checkbox:true,
	        rownumbers:true,
	        /* onRenderComplete: function () {
	        	iframeResize ();
	        } */
	        onAfterShowData: function () {
	            $(".gridTip").grid_ligerTip();
	            SetIframe_height ();
	        }
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         console.log(data);
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	         if($("#expStDt").val()>$("#expEndDt").val()){
	        	 $.ligerDialog.SQalert({content: "有效日期(起)不能大于有效日期(止)" , SQ_type: "warning" });
	        	 return;
	         }
	        grid.reload();
	    });
	    $("#clearBtn").click(function(event) {
	        $("#resetBtn").click();  //重置 input-text
	        var form = liger.get("searchBar");
	    });
	});
	    
	 //新增数据
	function add(){
		var callback = function () {
			grid.reload();
        };
        Add_navTab("PrjCfg_1", "新增报价方案", '<%=path%>/project/prjQuatPrpsCfgM/toAddPage.do', callback);
	}
	 //修改数据
	function change(_id){
		if(!_id)return;
		var callback = function () {
			grid.reload();
        };
		Add_navTab('PrjCfg_2'+_id, "修改报价方案", '<%=path%>/project/prjQuatPrpsCfgM/toAddPage.do?id='+_id, callback);
	}
	//详情
	function showDetail(_id){
		if(!_id)return;
		Add_navTab('PrjCfg_3'+_id, "报价方案详情", '<%=path%>/project/prjQuatPrpsCfgM/toDetailPage.do?id='+_id);
	}
	//删除数据
	function deleteRecord(id){
		if(!id)return;
		/* var selectedRows = grid.getSelectedRows();
		if(selectedRows.length == 0){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
			return;
		} */
		var _ids = [];
		/* for ( var index in selectedRows) {
			_ids.push(selectedRows[index].id);
		} */
		_ids.push(id);
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/project/prjQuatPrpsCfgM/removeByIds.do',
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			    },
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//启用
	function enable(id){
		if(!id) return;
   		$.ligerDialog.confirm(LogUtils.LOG_CMM_ENABLE_CONFIRM, function (flag) {
   			if(flag == false)return;
   			var wait_dialog;
   			$.ajax({
   				type: 'post',
   				dataType:'json',
   				data:{id:id},
   				url: '<%=path%>/project/prjQuatPrpsCfgM/enable.do',
   				beforeSend: function(){
   				 wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
   				},
   				success:function(msg){
   					 wait_dialog.close();
   					 if(msg.success == 1){
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
   						 grid.reload();
   					 }else{
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
   					 }
   				}
   			});
   		});
	}
	//禁用
	function disable(id){
   	 	if(!id)return;
   		$.ligerDialog.confirm(LogUtils.LOG_CMM_DISABLE_CONFIRM, function (flag) {
   			if(flag == false)return;
   			var wait_dialog;
   			$.ajax({
   				type: 'post',
   				dataType:'json',
   				data:{id:id},
   				url: '<%=path%>/project/prjQuatPrpsCfgM/disable.do',
   				beforeSend: function(){
   				 wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
   				},
   				success:function(msg){
   					 wait_dialog.close();
					 if(msg.success == 1){
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 grid.reload();
					 }else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
   				}
   			});
   		});
	}
	
</script>

<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <div class="label">方案配置名称</div>
                <div class="field">
                    <input name="prpsCfgNm" id="prpsCfgNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">有效日期</div>
                <div class="field">
                    <input name="expStDt" id="expStDt" type="text" class="ui-datepicker" value="" >
                     - 
                    <input name="expEndDt" id="expEndDt" type="text" class="ui-datepicker" value="" >
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox formBtns notRight">
                <span id="searchBtn" class="sq-button-round">查询</span>
                <span id="clearBtn" class="sq-button-round">清空</span>
                <span id="addBtn" class="sq-button-round" onclick="add();">新增</span>
                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
            </div>
        </div>
    </form>
</div>
</div>
<div id="ligergrid1" class="sq-grid"></div>


</body>
</html>